package com.ruoyi.web.controller.wokerSys;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.worker.domain.workAttendance.AttendanceSalary;
import com.ruoyi.worker.service.workerSys.AttendanceSalaryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName AttendanceSalaryApi
 * @Description 长期工工资计算
 * @Author leizhang
 * Date 2021/11/28 6:49 下午
 * @Version 1.0
 **/
@RestController
@RequestMapping("/attendanceSalaryApi")
@Slf4j
public class AttendanceSalaryApi extends BaseController {

    @Resource
    private AttendanceSalaryService attendanceSalaryService;

    /**
     * @Description : 长期工工资计算保存
     * @Author : leizhang
     * @Date 6:54 下午 2021/11/28
     * @param
     * @return com.ruoyi.common.core.domain.AjaxResult
     **/
    @PostMapping("/saveAttendanceSalary")
    public AjaxResult saveAttendanceSalary(@RequestBody AttendanceSalary attendanceSalary) {
        int result = attendanceSalaryService.attendanceSalaryCalculate(attendanceSalary);
        if(result == 1) {
            return AjaxResult.success("考勤生成成功");
        }else if (-1 == result) {
            return AjaxResult.error("考勤数据为空");
        }else{
            return AjaxResult.success();
        }
    }

    /**
     * 查询长期工工资列表
     */
    @GetMapping("/list")
    public TableDataInfo list(AttendanceSalary rzAttendanceSalary) {
        startPage();
        List<AttendanceSalary> list = attendanceSalaryService.selectRzAttendanceSalaryList(rzAttendanceSalary);
        return getDataTable(list);
    }

    /**
     * 获取长期工工资详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") int id) {
        return AjaxResult.success(attendanceSalaryService.selectRzAttendanceSalaryById(id));
    }

    /**
     * 修改长期工工资
     */
    @Log(title = "长期工工资", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AttendanceSalary rzAttendanceSalary) {
        return toAjax(attendanceSalaryService.updateRzAttendanceSalary(rzAttendanceSalary));
    }

    /**
     * 导出长期工工资单列表
     */
    @Log(title = "导出长期工工资单列表", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AttendanceSalary rzAttendanceSalarySum) {
        List<AttendanceSalary> list = attendanceSalaryService.selectRzAttendanceSalaryList(rzAttendanceSalarySum);
        ExcelUtil<AttendanceSalary> util = new ExcelUtil<AttendanceSalary>(AttendanceSalary.class);
        return util.exportExcel(list, "导出长期工工资单列表");
    }
}
